<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use App\Http\Query\PschangeQuery;

class PschangeController extends Controller
{

    function doPschange(Request $request)
    {
        $login_id = $request->cookie('login_id');

        $oldpassword = $request->input('oldpassword', '');
        $newpassword = $request->input('newpassword', '');
        if (empty($oldpassword) || empty($newpassword) || empty($login_id))
            return;
        $pschangeQuery = new PschangeQuery();
        $users = $pschangeQuery->getUserInfoByLoginId($login_id);

        if ($users[0]->password === $oldpassword) {
            $pschangeQuery->updPschangeMaster($login_id, $newpassword);
            return redirect('/login')->with('success', '添加成功！');
        } else {
            session([
                'errorCode' => Config::get('const.errorCode1')
            ]);
            return redirect('login');
        }
    }

    public function pschange(Request $request)
    {
        return view('admin.pschange');
    }
}
